package com.jackaltsc.mydemolist.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.jackaltsc.mydemolist.R;

/**
 * 一般的ListView 适配器是ArrayAdapter
 * Created by JackalTsc on 2016/7/13.
 */
public class ListView1Activity extends Activity {

    private int DATASIZE = 10;
    private ListView mListView;
    //数据
    private String[] mData = new String[DATASIZE];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_listview1);

        initView();

    }

    private void initView() {

        //模拟获取数据
        getData();

        mListView = (ListView) findViewById(R.id.lv_students);

        //构建ArrayAdapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,
                mData);

        //设置适配器
        mListView.setAdapter(adapter);
    }

    private void getData() {
        for (int i = 0; i < DATASIZE; i++) {
            mData[i] = "王尼玛" + i;
        }
    }
}
